# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django import forms
from django.utils.translation import ugettext_lazy as _

class CardForm(forms.Form):
    quantity = forms.IntegerField(label=_(u"购买数量"))
    message = forms.CharField(label=_(u"留言"),widget=forms.Textarea,required=False)
    def __init__(self, user=None, *args, **kwargs):
        self.user = user
        super(CardForm, self).__init__(*args, **kwargs)
        
    def clean(self):
        from registration.models import get_profile
        limit = get_profile(self.user)[0]
        quantity = self.cleaned_data.get('quantity')
        if quantity < limit:
            raise forms.ValidationError(_("最低购买%s张" % limit))
        return self.cleaned_data